<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="com.hz.supermanage.dao.*,com.hz.supermanage.bean.*" %>
<%
request.setCharacterEncoding("UTF-8");
    boolean bOrgAdmin = true;//SecurityMgr.isOrgAdmin(oaUser);
    String key = request.getParameter("key");
    System.out.println(key);
    //if (key.indexOf("@") != -1) {
    //     request.getRequestDispatcher("unit_role_xml.jsp").forward(request, response);
    //     return;
    //}
    OrganizationDao dao= new OrganizationDao();
%>
<?xml version="1.0" encoding="UTF-8"?>
<tree>
    <%
try {
             if ("0".equals(key)) { //读取根节点
    %>
    <node key="ROOT" name="行政组织架构" hasChild="<%=dao.isHasRoot()%>" url="R" icon="/parts/images/img/root.gif">
        <%
            //只有是根单位管理员才显示全部的单位
            Collection emList = null;
            if (bOrgAdmin) {
                emList = new ArrayList();
                emList = dao.getOrgNode("-1");
            }else {
                emList = new ArrayList();
                //根据用户所属部门查询
                //emList.add(getOrgNode(oaUser.getOrganization().getPrimaryKey()));
            }
            for (Iterator iterator = emList.iterator(); iterator.hasNext();) {
            	Hzsysorganization dep = (Hzsysorganization) iterator.next();
                boolean hasChild = dao.isHasChild(dep.getDepid());

        %>

        <node key="<%=dep.getDepid()%>" name="<%=dep.getDepname()%>"
              hasChild="<%=hasChild%>" urls="<%=dep.getUrl()%>"
              url="<%=dep.getDeptype()%>"
              icon="<%=dao.getNodeIcon(dep.getDeptype())%>">
            <%
                if (hasChild) {
                    Collection childs = dao.getChildNodes(dep.getDepid().toString());
                    for (Iterator iterator1 = childs.iterator(); iterator1.hasNext();) {
                    	Hzsysorganization dep1 = (Hzsysorganization) iterator1.next();
                        boolean hasChild1 = dao.isHasChild(dep1.getDepid());
            %>
            <node key="<%=dep1.getDepid()%>" name="<%=dep1.getDepname()%>"
                  hasChild="<%=hasChild1%>" urls="<%=dep1.getUrl()%>"
                  url="<%=dep1.getDeptype()%>"
                  icon="<%=dao.getNodeIcon(dep1.getDeptype())%>"/>
            <%
                    }
                }
            %>
        </node>
        <%
            }  //end for
        %>

    </node>

    <node key="LOST" name="无岗位用户" hasChild="false" url="L" icon="/parts/images/img/nopos.gif"/>

    <%--<node key="Role@Tree" name="权限模块" hasChild="true" url="Role" icon="/parts/images/img/role.gif"/>
    --%><%
    } else { //非根节点请求


        Collection emList = dao.getChildNodes(key);
        for (java.util.Iterator iterator = emList.iterator(); iterator.hasNext();) {
        	Hzsysorganization map = (Hzsysorganization) iterator.next();

    %>
    <node key="<%=map.getDepid()%>" name="<%=map.getDepname()%>"
          hasChild="<%=dao.isHasChild(map.getDepid().toString())%>" urls="<%=map.getUrl()%>"
          url="<%=map.getDeptype()%>"
          icon="<%=dao.getNodeIcon(map.getDeptype())%>"/>
    <%
        } //end for

     }
} catch(Exception e){
	e.printStackTrace();
}
    %>
</tree>